package com.cty;

import com.cty.Repository.UserRepository;
import com.cty.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;

import java.util.List;

@SpringBootTest(classes = Main.class)
public class testDQM {


    @Autowired
    private UserRepository userRepository;
    @Test
    public void test01() {
        User user = userRepository.findByUserName("张三");
        System.out.println(user);
    }

    @Test
    public void test02() {
        User user = userRepository.findByUserNameAndPassword("张三","12356");
        System.out.println(user);
    }


    @Test
    public void test03() {
        List<User> users = userRepository.findByUserNameOrPassword("李四", "123456");
        users.forEach(System.out::println);
    }

    @Test
    public void test04() {
        List<User> users = userRepository.findByUserNameIsNull();
        users.forEach(System.out::println);
    }

    @Test
    public void test05() {
        Page<User> userPage = userRepository.findAllByUserName("张三", PageRequest.of(1,2,Sort.by(Sort.Order.desc("userName"))));

        // 获得总的数据量
        System.out.println(userPage.getTotalPages());
        // 获得分页查询的内容
        List<User> content = userPage.getContent();
        for(User user: content) {
            System.out.println(user);
        }
        // 获得页码
        System.out.println(userPage.getNumber());
        //获得每页的数据量
        System.out.println(userPage.getSize());
    }
}
